using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace GoogleImageProxy
{
    public class TransferCountEventArgs : EventArgs
    {
        public TransferCountEventArgs():base()
        {
        }
        public TransferCountEventArgs(int transfered_, int totalTransferd_)
            : base()
        {
            transfered = transfered_;
            totalTransferd = totalTransferd_;
        }
        private int transfered;

        public int Transfered
        {
            get { return transfered; }
            set { transfered = value; }
        }
        private int totalTransferd;

        public int TotalTransferd
        {
            get { return totalTransferd; }
            set { totalTransferd = value; }
        }

    }


    public delegate void ReportTransferCount(int bytes);

    class StreamCopyHelper
    {
        

        const int BUFF_LEN = 1024;
        public static int CopyStream(Stream input, Stream output)
        {
            int transfered = 0;
            byte[] buffer = new byte[BUFF_LEN];
            while (true)
            {
                int read = input.Read(buffer, 0, buffer.Length);
                if (read <= 0)
                    return transfered;
                output.Write(buffer, 0, read);
                transfered += read;
            }
           
        }

        public static int CopyStream(Stream input, Stream output,ReportTransferCount rtc)
        {
            int transfered = 0;
            byte[] buffer = new byte[BUFF_LEN];
            while (true)
            {
                int read = input.Read(buffer, 0, buffer.Length);
                if (read <= 0)
                    return transfered;
                output.Write(buffer, 0, read);
                transfered += read;
                rtc(read);
            }
        }

    }
}
